package com.gas.gm.pdu.msg;

import com.gas.gm.model.Message;
import com.gas.gm.util.ChannelConfigurator;
import com.logica.smpp.pdu.SubmitMultiSM;
import com.logica.smpp.pdu.SubmitSM;

public class GasMessageRequestConverter implements MessageRequestConverter {

	public Message composeSingleMessage(SubmitSM request) {
		Message message=new Message();
		
		message.setServiceType(request.getServiceType());
		message.setSourceAddress(request.getSourceAddr().getAddress());
		message.setDestinationAddress(request.getDestAddr().getAddress());
		message.setShortMessage(request.getShortMessage());
		message.setMessageChannel(ChannelConfigurator.fix(message.getDestinationAddress()));
		return message;
	}

	public Message[] composeMultiMessage(SubmitMultiSM request,String systemId) {
		//SubmitMultiSM multiSM=(SubmitMultiSM)request;
		int addcount=request.getNumberOfDests();
		Message[] messages = new Message[addcount];
		for(int i=0;i<messages.length;i++)
		{
			messages[i]=new Message();
			messages[i].setSystemId(systemId);
			messages[i].setServiceType(request.getServiceType());
			messages[i].setSourceAddress(request.getSourceAddr().getAddress());
			messages[i].setDestinationAddress(request.getDestAddress(i).getAddress().getAddress());
			messages[i].setShortMessage(request.getShortMessage());
			messages[i].setMessageChannel(ChannelConfigurator.fix(messages[i].getDestinationAddress()));
		}
		return messages;
	}

}
